package org.game.db.bean;

import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.cfg.HeroCfg;
import org.apache.commons.lang3.ArrayUtils;
import java.util.HashMap;
import com.google.common.collect.Maps;
import com.sojoys.artifact.build.data.base.BasePojo;
import static org.game.db.StaticResource.HeroResource.*;
import java.sql.SQLException;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.vo.EquipmentVO;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import org.game.db.cache.HeroCache;
import org.cfg.cache.HeroCfgCache;
import static org.game.db.StaticResource.HeroResource.*;
/**
 * 英雄
 */
public class Hero extends BasePojo<Hero> {
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[2];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 配置ID
	*/
	private int cid;
	
	/**
	* 经验
	*/
	private long exp;
	
	/**
	* 英雄等级
	*/
	private int lvl;
	
	/**
	* 突破等级
	*/
	private int advancedLvl;
	
	/**
	* 天使等级
	*/
	private int angelLvl;
	
	/**
	* 进阶次数(升品次数)
	*/
	private int upQuality;
	
	/**
	* 玩家ID
	*/
	private int playerId;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	/**
	* 天使技能详情等级
	*/
	private Map angel;
	
	
	@Deprecated
	public static Hero builder() {
		Hero hero = new Hero();
		return hero;
	}
	
	@Deprecated
	public Hero() {
		super();
	}
	
	public Hero(long id, int cid, long exp, int lvl, int advancedLvl, int angelLvl, int upQuality, int playerId, Map angel) {
		super();
		this.id = id;
		this.cid = cid;
		this.exp = exp;
		this.lvl = lvl;
		this.advancedLvl = advancedLvl;
		this.angelLvl = angelLvl;
		this.upQuality = upQuality;
		this.playerId = playerId;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
		this.angel = angel;
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public Hero setId(long id) {this.id = id;return this;}
	
	/**
	 * 配置ID
	 */
	public int getCid() {return cid;}
	
	/**
	 * 配置ID
	 */
	public Hero setCid(int cid) {this.cid = cid;return this;}
	
	/**
	 * 经验
	 */
	public long getExp() {return exp;}
	
	/**
	 * 经验
	 */
	public Hero setExp(long exp) {this.exp = exp;return this;}
	
	/**
	 * 英雄等级
	 */
	public int getLvl() {return lvl;}
	
	/**
	 * 英雄等级
	 */
	public Hero setLvl(int lvl) {this.lvl = lvl;return this;}
	
	/**
	 * 突破等级
	 */
	public int getAdvancedLvl() {return advancedLvl;}
	
	/**
	 * 突破等级
	 */
	public Hero setAdvancedLvl(int advancedLvl) {this.advancedLvl = advancedLvl;return this;}
	
	/**
	 * 天使等级
	 */
	public int getAngelLvl() {return angelLvl;}
	
	/**
	 * 天使等级
	 */
	public Hero setAngelLvl(int angelLvl) {this.angelLvl = angelLvl;return this;}
	
	/**
	 * 进阶次数(升品次数)
	 */
	public int getUpQuality() {return upQuality;}
	
	/**
	 * 进阶次数(升品次数)
	 */
	public Hero setUpQuality(int upQuality) {this.upQuality = upQuality;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 */
	public Hero setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected Hero setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected Hero setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	/**
	 * 天使技能详情等级
	 */
	public Map getAngel() {return angel;}
	
	/**
	 * 天使技能详情等级
	 */
	public Hero setAngel(Map angel) {this.angel = angel;return this;}
	
	/**
	 * 天使技能详情等级
	 */
	public byte[] getAngelByte() {
		return toBytes(angel);
	}
	
	/**
	 * 天使技能详情等级
	 */
	public Map initAngelByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	
	// 代理
	private org.game.db.proxy.bean.HeroProxy heroProxy = new org.game.db.proxy.bean.HeroProxy().build(this);
	
	public org.game.db.proxy.bean.HeroProxy getHeroProxy(){return heroProxy;}
	
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.cid;
        values[2] = this.exp;
        values[3] = this.lvl;
        values[4] = this.advancedLvl;
        values[5] = this.angelLvl;
        values[6] = this.upQuality;
        values[7] = this.playerId;
        values[8] = this.createDate;
        values[9] = this.modifiedDate;
        values[10] = this.angel;
        return values;
	}
	
	public Hero deepCopy(){
		Hero hero = null;
		try {
			hero = (Hero) super.clone();
		    hero.setCreateDate(ToolCopy.copyObject(this.createDate));
		    hero.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    hero.setAngel(ToolCopy.copyObject(this.angel));
		    // 克隆索引
		    hero.indexValues = ArrayUtils.clone(indexValues);
			return hero;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return hero;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.cid);
        map.put(keys[2], this.exp);
        map.put(keys[3], this.lvl);
        map.put(keys[4], this.advancedLvl);
        map.put(keys[5], this.angelLvl);
        map.put(keys[6], this.upQuality);
        map.put(keys[7], this.playerId);
        map.put(keys[8], this.createDate);
        map.put(keys[9], this.modifiedDate);
        map.put(keys[10], this.angel);
        return map;
    }
    
    protected Hero createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.cid = (int)map.get(keys[1]);
   		this.exp = (long)map.get(keys[2]);
   		this.lvl = (int)map.get(keys[3]);
   		this.advancedLvl = (int)map.get(keys[4]);
   		this.angelLvl = (int)map.get(keys[5]);
   		this.upQuality = (int)map.get(keys[6]);
   		this.playerId = (int)map.get(keys[7]);
   		this.createDate = (java.util.Date)map.get(keys[8]);
   		this.modifiedDate = (java.util.Date)map.get(keys[9]);
   		this.angel = (Map)map.get(keys[10]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.cid);
        obj.put(keys[2], this.exp);
        obj.put(keys[3], this.lvl);
        obj.put(keys[4], this.advancedLvl);
        obj.put(keys[5], this.angelLvl);
        obj.put(keys[6], this.upQuality);
        obj.put(keys[7], this.playerId);
        obj.put(keys[8], this.createDate);
        obj.put(keys[9], this.modifiedDate);
        obj.put(keys[10], toBytes(angel));
        return obj;
    }
    
    protected Hero createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.cid = obj.getIntValue(keys[1]);
	    this.exp = obj.getLongValue(keys[2]);
	    this.lvl = obj.getIntValue(keys[3]);
	    this.advancedLvl = obj.getIntValue(keys[4]);
	    this.angelLvl = obj.getIntValue(keys[5]);
	    this.upQuality = obj.getIntValue(keys[6]);
	    this.playerId = obj.getIntValue(keys[7]);
	    this.createDate = obj.getDate(keys[8]);
	    this.modifiedDate = obj.getDate(keys[9]);
		this.angel = (Map)forBytesObject(obj.getBytes(keys[10]));
        return this;
    }
    
    
    public Hero createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.cid = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.exp = rs.getLong(SOURCE_COLUMN_NAMES[2]);
	    this.lvl = rs.getInt(SOURCE_COLUMN_NAMES[3]);
	    this.advancedLvl = rs.getInt(SOURCE_COLUMN_NAMES[4]);
	    this.angelLvl = rs.getInt(SOURCE_COLUMN_NAMES[5]);
	    this.upQuality = rs.getInt(SOURCE_COLUMN_NAMES[6]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[7]);
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[8]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[9]);
		this.angel = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[10]));
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.cid);
	    byteBuf.writeLong(this.exp);
	    byteBuf.writeInt(this.lvl);
	    byteBuf.writeInt(this.advancedLvl);
	    byteBuf.writeInt(this.angelLvl);
	    byteBuf.writeInt(this.upQuality);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
	    byteBuf.writeObject(this.angel);
    }
	
	protected Hero readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.cid = byteBuf.readInt(null);
	    this.exp = byteBuf.readLong(null);
	    this.lvl = byteBuf.readInt(null);
	    this.advancedLvl = byteBuf.readInt(null);
	    this.angelLvl = byteBuf.readInt(null);
	    this.upQuality = byteBuf.readInt(null);
	    this.playerId = byteBuf.readInt(null);
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    this.angel = (Map)byteBuf.readObject();
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public Hero insert(){
    	return HeroCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public Hero update(){
    	return HeroCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return HeroCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public Hero insertAndFlush(){
    	return HeroCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public Hero updateAndFlush(){
    	return HeroCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return HeroCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public Hero syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}